<?php
/**
 * True Gallery Component for Joomla CMS
 *
 * @version 2.5
 * @author Alexey N. Brin (userxp@joomlaportal.ru)
 * @author Dmitry Smirnov (mitrich@joomlaportal.ru)
 * @homepage http://truegallery.ru 
 * @filename true.legacy.php
 * @package True Gallery
 * @copyright (C) 2008-2009 by joomlatune.ru
 * @license GNU/GPL: http://www.gnu.org/copyleft/gpl.html
 * 
 * THIS GALLERY is an EVOLUTION of AkoGallery -> PonyGallery -> DatsoGallery
 *
 * If you fork this to create your own project, 
 * please make a reference to True Gallery someplace in your code 
 * and provide a link to http://www.joomlatune.ru
 *
 **/
 
// ensure this file is being included by a parent file
(defined ( '_VALID_MOS' ) or defined ( '_JEXEC' )) or die ( 'Direct Access to this location is not allowed.' );

if( ! defined ( 'DS' )) {
	define ( 'DS', DIRECTORY_SEPARATOR );
}

if( !defined ( 'JOOMLA_JVERSION' ) ) {
	if( defined ( '_JEXEC' ) && class_exists ( 'JApplication' )) {
		
		if( !defined ( '_ISO' ) ) {
			define ( '_ISO', 'charset=utf-8' );
		}
		
		define( 'JOOMLA_JVERSION',		'1.5' );
		define( 'JOOSTINA_JVERSION',	false );
		define( 'TRUE_INDEX2',			JTuneConfig::buildPath(1,0) . 'index.php?option='.TG_CMP );
		
		// needed on installation
		$language = &JFactory::getLanguage();
		$lang_file = JPATH_ADMINISTRATOR.DSX.'language'.DSX.$language->_lang.DSX.$language->_lang.'.'.TG_CMP.'.ini';
		$language->_load( $lang_file, TG_CMP );
		
		// including support files for old functions
		$system_legacy_path = JTuneConfig::buildPath(0,1).'plugins'.DSX.'system'.DSX.'legacy'.DSX;
		require_once( $system_legacy_path.'functions.php' );
		require_once( $system_legacy_path.'html.php' );
		require_once( $system_legacy_path.'commonhtml.php' );

	}
	else {
		global $mosConfig_lang, $mainframe;
		$lang = $mosConfig_lang;
		define( 'JOOMLA_JVERSION', '1.0' );
		
		if( isset( $_VERSION->CMS ) && @$_VERSION->CMS=='Joostina' ) {
			define( 'JOOSTINA_JVERSION', $_VERSION->CMS_ver );
		}
		else {
			define( 'JOOSTINA_JVERSION', false );
		}
		
		define ( 'TRUE_INDEX2', JTuneConfig::buildPath(1,0) . 'index2.php?option='.TG_CMP );
		require_once( TG_JTUNE.'localization'.DSX.'string.php');
		require_once( TG_JTUNE.'localization'.DSX.'language.php');
		
		if( !is_file( TG_ADMINPATH.'languages'.DSX.$lang.'.ini' ) ) {
			$lang = 'english';
		}
		
		$language = &JoomlaTuneLanguage::getInstance();
		$language->setRoot( TG_ADMINPATH . 'languages' );
		$language->load( $lang );
		
		$joomfishpath = JTuneConfig::buildPath(1,1,'com_joomfish');
		$joomfish = $joomfishpath.'joomfish.php';
		
		// small hack for JoomFish 1.8.2+ on Joomla 1.0.x
		if( is_file($joomfish) ) {
			include_once( $joomfishpath.'joomfish.class.php' );
			include_once( $joomfishpath.'libraries'.DSX.'joomla'.DSX.'language.php' );
			
			if( class_exists ( 'JLanguageHelper' ) ) {
				if( isset($mainframe) && $mainframe->isAdmin() ) {
					//$jfm = new JoomFishManager( $mosConfig_absolute_path . DSX . 'administrator' . DSX . 'components' . DSX . 'com_joomfish' );
					$jfm = new JoomFishManager( substr( $joomfishpath, 0, -1 ) );
					$adminLang = strtolower( $jfm->getCfg( 'componentAdminLang' ) );
					$lng = & JLanguageHelper::getLanguage( $adminLang );
				} else {
					$lng = & JLanguageHelper::getLanguage();
				}
				
				if( is_array( $lng->_strings ) && is_array( $language->languages[$lang] ) ) {
					$lng->_strings = array_merge( $lng->_strings, $language->languages[$lang] );
				}
			}
		}
		else {
			if( !class_exists('JText') ) {
				class JText{
					function _($text, $jsSafe = false) {
						$lang = &JoomlaTuneLanguage::getInstance();
						return $lang->_( $text, $jsSafe );
					}
					
					function sprintf($string) {
						$lang = &JoomlaTuneLanguage::getInstance();
						$args = func_get_args ();
						if( count($args) > 0) {
							$args [0] = $lang->_( $args [0] );
							return call_user_func_array ( 'sprintf', $args );
						}
						return '';
					}
				}
			}
			
			if( class_exists('JLanguageHelper') ) {
				// small hack for JoomFish 1.8.2+ on Joomla 1.0.x
				$lng = &JLanguageHelper::getLanguage();
				if( is_array($lng->_strings) && is_array($language->languages[$lang])) {
					$lng->_strings = array_merge ( $lng->_strings, $language->languages[$lang] );
				}
			}
		}
	}
}

?>